package com.sgb.goods.viewmodel;

import androidx.lifecycle.MutableLiveData;

import com.sgb.goods.api.GoodsCallBack;
import com.sgb.goods.api.GoodsNet;
import com.sgb.goods.entity.CommitVipPrice;
import com.sgb.goods.entity.MemberPriceEntity;
import com.sgb.goods.entity.SkuDetail;
import com.sgb.goods.utils.base.viewmodel.BaseViewModel;
import com.sgb.goods.view.adapter.MemberPriceAdapter;
import com.sgb.goods.view.adapter.MemberPriceDetailsAdapter;
import com.swgk.core.base.model.entity.BaseEntity;
import com.swgk.core.util.MToast;

import java.util.List;

/**
 * 新增会员报价
 * @author cyj
 */
public class AddMemberGoodsModel extends BaseViewModel {

    public MemberPriceAdapter adapter;
    public MemberPriceDetailsAdapter mAdapter;
    //会员价详情
    public MutableLiveData<MemberPriceEntity> detail = new MutableLiveData<>();
    public MutableLiveData<List<MemberPriceEntity.MemberPriceSkuDetail>> detailSku = new MutableLiveData<>();
    //新增商品会员价
    public MutableLiveData<List<SkuDetail.SkuListEntity>> skuList = new MutableLiveData<>();
    public MutableLiveData<SkuDetail> addSkuDetail = new MutableLiveData<>();
    public MutableLiveData<Integer> ShowLoading = new MutableLiveData<>();
    public MutableLiveData<CommitVipPrice> commitData = new MutableLiveData<>();
    public MutableLiveData<Integer> status = new MutableLiveData<>();
    private List<String> list;

    public AddMemberGoodsModel() {
        adapter = new MemberPriceAdapter();
        mAdapter = new MemberPriceDetailsAdapter();
    }

    /**
     * 用户中心 会员价详情
     */
    public void getMemberPriceDetails(long itemMemberId, long itemId) {
        showLoading();
        GoodsNet.getInstance().getMemberPriceApi().getMemberPriceDetails(itemMemberId, itemId).enqueue(new GoodsCallBack<BaseEntity<MemberPriceEntity>>() {
            @Override
            public void onSuccess(BaseEntity<MemberPriceEntity> data) {
                detail.postValue(data.getData());
            }
        });
    }

    /**
     * 获取sku会员价详情信息
     */
    public void getSkuMemberPriceDetail(long itemMemberNo, long skuId) {
        showLoading();
        GoodsNet.getInstance().getMemberPriceApi().getSkuMemberPriceDetail(itemMemberNo, skuId).enqueue(new GoodsCallBack<BaseEntity<List<MemberPriceEntity.MemberPriceSkuDetail>>>() {
            @Override
            public void onSuccess(BaseEntity<List<MemberPriceEntity.MemberPriceSkuDetail>> data) {
                detailSku.postValue(data.getData());
            }
        });
    }

    /**
     * 用户中心 会员价详情
     */
    public void getSkuList(long itemId) {
        showLoading();
        GoodsNet.getInstance().getMemberPriceApi().getSkuList(itemId).enqueue(new GoodsCallBack<BaseEntity<SkuDetail>>() {
            @Override
            public void onSuccess(BaseEntity<SkuDetail> data) {
                skuList.postValue(data.getData().skuListVos);
                addSkuDetail.postValue(data.getData());
            }
        });
    }

    /**
     * 提交会员价
     */
    public void commitVipPrice() {
        showLoading();
        GoodsNet.getInstance().getMemberPriceApi().commitVipPrice(commitData.getValue()).enqueue(new GoodsCallBack<BaseEntity>() {
            @Override
            public void onSuccess(BaseEntity data) {
                MToast.showToast(application.getApplicationContext(), "提交成功");
                status.postValue(Integer.valueOf(data.getCode()));
            }
        });
    }
}
